Imports DAL
Imports MyClasses
Imports System.Configuration

Public Class frmFirm
    'Dim intPersonID As Integer
    'Dim intAddress As Integer
    Dim address(0) As CAddress
    'Dim blnFlagAddType As Boolean
    Dim blnCountryFlag As Boolean
    Dim blnStateFlag As Boolean
    Dim blnCityFlag As Boolean
    Dim flgUpdt As Boolean
    Private _blnMDI As Boolean
    Dim updtAddress(0) As CAddress
    Dim btClose As Byte   'USED WHILE CLOSE IF DATA IS SAVED SET IT 1 ,IF IT IS 0 THEN CHECK DIRTY

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        If ValidateData() = False Then Exit Sub
        Call UpdateData()
    End Sub

    Public ReadOnly Property CanMDIClose() As Boolean
        Get
            Return _blnMDI
        End Get
    End Property

    Private Function UpdateData() As Boolean
        Dim objFirm As CFirm
        Dim blnResult As Boolean
        Try
            objFirm = SetData()
            If btnUpdate.Text <> "&Update" Then
                blnResult = BFirm.SaveFirm(objFirm, "S", SetAddress(), flgUpdt)
                If blnResult = True Then
                    BCommon.ShowMsgError(3)
                    _blnMDI = True
                    btClose = 1
                    Me.Close()
                Else : BCommon.ShowMsgError(4)
                End If

            Else
                blnResult = BFirm.SaveFirm(objFirm, "U", SetAddress(), flgUpdt)
                If blnResult = True Then
                    BCommon.ShowMsgError(5)
                    btClose = 1
                    _blnMDI = True
                    Me.Close()
                Else : BCommon.ShowMsgError(4)
                End If
            End If
                Return blnResult
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SaveData")
            Return False
        End Try
    End Function

    Private Sub Getaddress()
        Try
            If IsNothing(address(0)) Then
                Exit Sub
            End If
            With address(0)
                txtAddr1.Text = .Description1
                txtAddr1.Tag = .Description1
                cmbCountry.SelectedValue = .Country
                cmbCountry.Tag = .Country
                cmbState.SelectedValue = .State
                cmbState.Tag = .State
                cmbCity.SelectedValue = .City
                cmbCity.Tag = .City
                txtPinCode.Text = .PinCode
                txtPinCode.Tag = .PinCode
                txtPhone1.Text = .PhoneNo1
                txtPhone1.Tag = .PhoneNo1
                txtPhone2.Text = .PhoneNo2
                txtPhone2.Tag = .PhoneNo2
                txtFax.Text = .Fax
                txtFax.Tag = .Fax
                txtEmail.Text = .EmailID
                txtEmail.Tag = .EmailID
                txtWebSite.Text = .WebSiteAddress
                txtWebSite.Tag = .WebSiteAddress
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "Getaddress")
        End Try
    End Sub

    'Display the data while the form is loaded
    Private Sub DisplayData()
        Try
            Dim dtbCountry As New DataTable
            Dim StartDT As String
            Dim EndDT As String

            Me.Text = "Firm Setup"
            dtpFinEnd.Enabled = False
            btnUpdate.Text = "&Save"
            dtbCountry = DAddress.GetCountryNew()
            BCommon.SetComboValues(cmbAddrType, "ADDRESS_TYPE")
            If dtbCountry.Rows.Count > 0 Then
                BCommon.SetComboValues(cmbCountry, dtbCountry, "CountryCD", "Description")
            End If
            txtFirmName.Tag = txtFirmName.Text
            txtShortName.Tag = txtShortName.Text
            txtLSTNo.Tag = txtLSTNo.Text
            txtCSTNo.Tag = txtCSTNo.Text
            txtFDA.Tag = txtFDA.Text

            StartDT = CType(System.DateTime.Today.Year + 1 & "-04-01", Date)
            EndDT = CType(System.DateTime.Today.Year & "-03-31", Date)

            If System.DateTime.Today.Date <= EndDT Then
                StartDT = CType(System.DateTime.Today.Year - 1 & "-04-01", Date)
                EndDT = CType(System.DateTime.Today.Year & "-03-31", Date)
            Else
                StartDT = CType(System.DateTime.Today.Year & "-04-01", Date)
                EndDT = CType(System.DateTime.Today.Year + 1 & "-03-31", Date)
            End If
            dtpFinStart.Value = StartDT
            dtpFinEnd.Value = EndDT
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "DisplayData")
        End Try
    End Sub

    'Rahul_ITS@29022008 Add to Set Financial Year
    Private Sub dtpFinStart_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpFinStart.LostFocus
        Dim StartDT As Date
        Dim EndDT As Date
        Try
            If Now.Date < dtpFinStart.Value Then
                BCommon.ShowMsgError(10429)
                dtpFinStart.Value = Now.Date
                dtpFinStart.Focus()
            Else
                StartDT = dtpFinStart.Value
                EndDT = dtpFinEnd.Value
                EndDT = CType(StartDT.Year + 1 & "-" & EndDT.Month & "-" & EndDT.Day, Date)
                dtpFinEnd.Value = EndDT
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "dtpFinStart_LostFocus")
        End Try
    End Sub

    Private Sub ViewAddress()
        Dim dtbAddr As New DataTable
        'Dim intaddID As Integer
        Try
            'intaddID = BFirm.GetFirmInfo()
            'dtbAddr = DAddress.SearchAddress(intPersonID)
            dtbAddr = BFirm.ShowAddr(BFirm.GetFirmInfo())
            If IsNothing(dtbAddr.Rows(0)) Then Exit Sub
            If dtbAddr.Rows.Count > 0 Then
                With dtbAddr.Rows(0)
                    address(0) = New CAddress
                    address(0).AddressType = .Item(0)
                    address(0).Description1 = .Item(1)
                    address(0).Description2 = .Item(2)
                    address(0).PinCode = .Item(3)
                    address(0).City = .Item(4)
                    address(0).State = .Item(5)
                    address(0).Country = .Item(6)
                    address(0).PhoneNo1 = .Item(7)
                    address(0).PhoneNo2 = .Item(8)
                    address(0).Fax = .Item(11)
                    address(0).EmailID = .Item(12)
                    address(0).WebSiteAddress = .Item(13)
                    'address(0).AddressID = .Item(14)
                End With
            End If
            If dtbAddr.Rows.Count > 0 Then
                If cmbAddrType.SelectedValue <> dtbAddr.Rows(0).Item(0) Then
                    'blnFlagAddType = False
                    cmbAddrType.SelectedValue = dtbAddr.Rows(0).Item(0)
                    'blnFlagAddType = True
                End If
                'intAddress = cmbAddrType.SelectedIndex
                CCommon.CopyArray(address, updtAddress) 'copy address array to updatearray
                Call Getaddress()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ViewAddress()")
        End Try
    End Sub
    '       Displays the State name according to the Country Name Selected
    Private Sub GetCountryState()
        Dim dtcountry As New DataTable
        Try
            If cmbCountry.SelectedIndex > 0 Then
                dtcountry = DAddress.GetCountryStates(cmbCountry.SelectedValue)
                blnStateFlag = False
                BCommon.SetComboValues(cmbState, dtcountry, "StateCD", "Description")
                blnStateFlag = True
                GetStateCity(cmbState.SelectedValue)
            End If

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "GetCountryState")
        End Try
    End Sub
    'Displays the city name according to the state selected
    Private Sub GetStateCity(ByVal intaddrS As Integer)
        Dim dtstate As New DataTable
        Try
            dtstate = DAddress.GetStateCity(intaddrS, cmbCountry.SelectedValue)
            blnCityFlag = False
            BCommon.SetComboValues(cmbCity, dtstate, "CityCD", "Description")
            blnCityFlag = True
            cmbCity.Refresh()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "GetStateCity")
        End Try
    End Sub
    '   Displays the pincode of the corresponding city
    Private Sub GetCityPincode(ByVal intaddrci As Integer)
        Dim intpincode As Integer
        Try
            intpincode = DAddress.GetCityPinCode(intaddrci)
            txtPinCode.Text = intpincode
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "GetCityPincode")
        End Try
    End Sub

    Private Function ValidateData() As Boolean

        If Trim(txtFirmName.Text) = "" Then
            BCommon.ShowMsgError(10247)
            txtFirmName.Text = ""
            txtFirmName.Focus()
            Return False
        End If

        If Trim(txtShortName.Text) = "" Then
            BCommon.ShowMsgError(10248)
            txtShortName.Text = ""
            txtShortName.Focus()
            Return False
        End If

        If Trim(txtLSTNo.Text) = "" Then
            BCommon.ShowMsgError(10064)
            txtLSTNo.Text = ""
            txtLSTNo.Focus()
            Return False
        End If

        If Trim(txtCSTNo.Text) = "" Then
            BCommon.ShowMsgError(10065)
            txtCSTNo.Text = ""
            txtCSTNo.Focus()
            Return False
        End If

        If Trim(txtFDA.Text) = "" Then
            BCommon.ShowMsgError(10249)
            txtFDA.Text = ""
            txtFDA.Focus()
            Return False
        End If

        'Kiran@ITS on 20071120:Added for Firm date should not greater than todays date.
        If Trim(dtpDate.Value) > Now() Then
            BCommon.ShowMsgError(10257)
            dtpDate.Value = Now.Date()
            dtpDate.Focus()
            Return False
        End If

        If (dtpFinEnd.Value.Year - dtpFinStart.Value.Year) > 1 OrElse (dtpFinEnd.Value.Year - dtpFinStart.Value.Year) < 1 Then
            BCommon.ShowMsgError(10403)
            dtpFinStart.Focus()
            Return False
        End If

        'Divya 21/01/2008 : Added following validation for Addr details if the screen is visited the very first time.
        If btnUpdate.Text = "&Save" Then
            If txtAddr1.Text = "" Or cmbCity.Text = "" Or txtPinCode.Text = "" Or txtPhone1.Text = "" Then
                BCommon.ShowMsgError(1005)
                If txtPhone1.Text = "" Then
                    txtPhone1.Focus()
                End If
                If txtPinCode.Text = "" Then
                    txtPinCode.Focus()
                End If
                If cmbCity.Text = "" Then
                    cmbCity.Focus()
                End If
                If txtAddr1.Text = "" Or txtAddr1.Text = Nothing Then
                    txtAddr1.Focus()
                End If
                Return False
            End If
        End If
        '>>End

        'Kiran@ITS on 20071211: Added for Website Address Validation 
        If Trim(txtWebSite.Text) <> "" Then
            If BCommon.ValidateWebAdd(txtWebSite.Text) = False Then
                txtWebSite.Focus()
                Return False
            End If
            ValidateData = True
        End If

        If Trim(txtEmail.Text) <> "" Then
            If BCommon.ValidateEmailID(txtEmail.Text) = False Then
                txtEmail.Focus()
                Return False
            End If
            ValidateData = True
        End If

        If Trim(txtPhone1.Text) <> "" Or Trim(txtPhone2.Text) <> "" Then
            If Trim(txtPhone1.Text) = Trim(txtPhone2.Text) Then
                BCommon.ShowMsgError(10002)
                txtPhone2.Focus()
                Return False
            End If
        End If

        If Trim(txtEmail.Text) <> "" Or Trim(txtWebSite.Text) <> "" Then
            If Trim(txtEmail.Text) = Trim(txtWebSite.Text) Then
                BCommon.ShowMsgError(10001)
                txtPhone2.Focus()
                Return False
            End If
        End If

        Return True
    End Function
    'Assign values to the CDoctor Object
    Private Function SetData() As CFirm
        Dim objFirm As New CFirm
        Try
            With objFirm

                .FirmName = Trim(txtFirmName.Text)
                .ShortName = Trim(txtShortName.Text)
                .LSTNUM = Trim(txtLSTNo.Text)
                .CSTNUM = Trim(txtCSTNo.Text)
                .FDA = Trim(txtFDA.Text)
                '.addID = BFirm.GetFirmAddressID(.person.PersonID)
                '.addID = BFirm.GetFirmAddressID(1)
                'Kiran@ITS on 20071121;Added for Insertion Into tfinyear
                .FinYStart = Trim(dtpFinStart.Value.Date())
                .FinYEnd = Trim(dtpFinEnd.Value.Date())
                .FirmSDt = Trim(dtpDate.Value.Date())
            End With
            Return objFirm
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetData")
            Return Nothing
        End Try
    End Function
    'Set the Address Information from controls to Address array
    Private Function SetAddress() As CAddress()

        Try
            Dim intAddressID As Integer
            intAddressID = BFirm.GetFirmInfo()
            If btnUpdate.Text = "&Save" Then
                If Not IsNothing(address(0)) Then
                    intAddressID = address(0).AddressID
                End If
            End If
            address(0) = New CAddress
            address(0).AddressID = intAddressID
            With address(0)
                .AddressType = Trim(cmbAddrType.SelectedValue)
                .Description1 = Trim(txtAddr1.Text)
                .Country = cmbCountry.SelectedValue
                .State = cmbState.SelectedValue
                .PinCode = IIf(Trim(txtPinCode.Text) <> "", Trim(txtPinCode.Text), 0)
                If cmbCity.SelectedValue = Nothing Then
                    If cmbCity.Text <> "" Then
                        .City = DAddress.SaveCity(.State, .Country, cmbCity.Text, .PinCode)
                    End If
                Else
                    .City = cmbCity.SelectedValue
                End If
                .PhoneNo1 = Trim(txtPhone1.Text)
                .PhoneNo2 = Trim(txtPhone2.Text)
                .Fax = Trim(txtFax.Text)
                .EmailID = Trim(txtEmail.Text)
                .WebSiteAddress = Trim(txtWebSite.Text)
            End With
            'End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetAddress")
        End Try
        Return address
    End Function

    Private Sub LoadData()
        Dim dtLoadData As New DataTable
        Try
            'blnFlagAddType = True
            blnCountryFlag = True
            blnStateFlag = True
            blnCityFlag = True
            _blnMDI = False
            Call DisplayData()
            dtLoadData = BFirm.GetData()
            If dtLoadData.Rows.Count > 0 Then
                flgUpdt = True
                btnUpdate.Text = "&Update"
                txtFirmName.Text = dtLoadData.Rows(0).Item("FirmName")
                txtShortName.Text = dtLoadData.Rows(0).Item("ShortTitle")
                txtLSTNo.Text = dtLoadData.Rows(0).Item("LSTNO")
                txtCSTNo.Text = dtLoadData.Rows(0).Item("CSTNO")
                txtFDA.Text = dtLoadData.Rows(0).Item("FDALicenseNo")
                dtpDate.Text = dtLoadData.Rows(0).Item("FirmStartDate")
                'Kiran@ITS on 20071120:Added for FinStart and End Date
                dtpFinStart.Value = dtLoadData.Rows(0).Item("fin_start_dt")
                dtpFinStart.Enabled = False
                dtpFinEnd.Value = dtLoadData.Rows(0).Item("fin_end_dt")
                dtpFinEnd.Enabled = False
                lblComp1.Visible = False
                lblComp2.Visible = False
                lblComp3.Visible = False
                lblComp4.Visible = False
                lblComp5.Visible = False
                lblComp6.Visible = False
                Call ViewAddress()
            Else
                flgUpdt = False
                txtFirmName.Text = ""
                txtShortName.Text = ""
                txtLSTNo.Text = ""
                txtCSTNo.Text = ""
                txtFDA.Text = ""
                txtAddr1.Text = ""
                cmbCountry.SelectedIndex = -1
                cmbState.SelectedIndex = -1
                txtPinCode.Text = ""
                txtPhone1.Text = ""
                txtPhone2.Text = ""
                txtFax.Text = ""
                txtEmail.Text = ""
                txtWebSite.Text = ""
                dtpDate.Value = Now.Date
                'dtpFinStart.Value = "01/04/" & Year(Now.Date)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "LoadData")
        End Try
    End Sub

    Private Sub txtfax_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFax.KeyDown
        Try
            'If e.Alt Then Exit Sub
            'If e.KeyCode = Keys.Enter Then txtEmail.Focus()
            'If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
            'e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM", False)

            If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
            If e.KeyCode = Keys.Enter Then txtEmail.Focus()
            If e.Shift = True Then
                If (e.KeyCode >= 48 And e.KeyCode <= 48 + 10) Or (e.KeyCode >= 96 And e.KeyCode <= 96 + 10) Then
                    e.SuppressKeyPress = True
                    Me.Cursor = Cursors.Default
                    Exit Sub
                End If
            End If
            If BCommon.ValidateMiscell(e.KeyCode, "QTY") = False Then e.SuppressKeyPress = True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtfax_KeyDown")
        End Try
    End Sub

    Private Sub txtphone1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone1.KeyDown
        Try
            'If e.Alt Then Exit Sub
            'If e.KeyCode = Keys.Enter Then txtPhone2.Focus()
            'If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
            'e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM", False)

            If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
            If e.KeyCode = Keys.Enter Then txtPhone2.Focus()
            If e.Shift = True Then
                If (e.KeyCode >= 48 And e.KeyCode <= 48 + 10) Or (e.KeyCode >= 96 And e.KeyCode <= 96 + 10) Then
                    e.SuppressKeyPress = True
                    Me.Cursor = Cursors.Default
                    Exit Sub
                End If
            End If
            If BCommon.ValidateMiscell(e.KeyCode, "QTY") = False Then e.SuppressKeyPress = True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtphone1_KeyDown")
        End Try
    End Sub

    Private Sub txtphone2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone2.KeyDown
        Try
            'If e.Alt Then Exit Sub
            'If e.KeyCode = Keys.Enter Then txtFax.Focus()
            'If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
            'e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM", False)

            If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
            If e.KeyCode = Keys.Enter Then txtFax.Focus()
            If e.Shift = True Then
                If (e.KeyCode >= 48 And e.KeyCode <= 48 + 10) Or (e.KeyCode >= 96 And e.KeyCode <= 96 + 10) Then
                    e.SuppressKeyPress = True
                    Me.Cursor = Cursors.Default
                    Exit Sub
                End If
            End If
            If BCommon.ValidateMiscell(e.KeyCode, "QTY") = False Then e.SuppressKeyPress = True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtphone2_KeyDown")
        End Try
    End Sub

    Private Sub txtPincode_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPinCode.KeyDown
        If e.Alt Then Exit Sub
        If e.KeyCode = Keys.Enter Then txtPhone1.Focus()
        If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
        e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM", False)
    End Sub

    Private Sub cmbState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbState.SelectedIndexChanged
        If blnStateFlag = False Then Exit Sub
        Call GetStateCity(cmbState.SelectedValue)
    End Sub

    Private Sub cmbCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCity.SelectedIndexChanged
        If blnCityFlag = False Then Exit Sub
        If cmbCity.Items.Count > 0 Then
            Call GetCityPincode(cmbCity.SelectedValue)
        End If
    End Sub

    Private Sub cmbcountry_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbCountry.KeyDown
        If e.KeyCode = Keys.Enter Then cmbState.Focus()
    End Sub

    Private Sub cmbCountry_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbCountry.GotFocus
        If cmbCountry.SelectedValue = Nothing Then
            cmbCountry.SelectedValue = ConfigurationManager.AppSettings("Country")
        End If
    End Sub

    Private Sub cmbAddrType_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbAddrType.KeyDown
        If e.KeyCode = Keys.Enter Then txtAddr1.Focus()
    End Sub

    Private Sub cmbcity_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbCity.KeyDown
        If e.KeyCode = Keys.Enter Then txtPinCode.Focus()
    End Sub

    Private Sub cmbstate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbState.KeyDown
        If e.KeyCode = Keys.Enter Then cmbCity.Focus()
    End Sub

    Private Sub frmFirm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Not (ConfigurationManager.AppSettings("FormMode") = "R") Then
                If btClose = 1 Then Exit Sub
                Call SetAddress()
                If isUpdate() Then
                    Select Case BCommon.ShowMsgError(10081, "YNC")
                        Case Windows.Forms.DialogResult.Yes
                            If ValidateData() Then
                                Call UpdateData()
                            Else
                                e.Cancel = True
                            End If
                        Case Windows.Forms.DialogResult.Cancel
                            e.Cancel = True
                        Case Windows.Forms.DialogResult.No
                    End Select
                End If
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnClose_Click")
        End Try
    End Sub

    Private Sub frmFirm_HelpButtonClicked(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.HelpButtonClicked
        'Rauhl_ITS@20073012 : Add following code display help
        Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Firm Setup")
        e.Cancel = True
    End Sub

    Private Sub frmFirm_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.F1 Then
            'Rauhl_ITS@20073012 : Add following code display help
            e.SuppressKeyPress = True
            Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Firm Setup")
        End If
    End Sub

    Private Sub frmFirm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Call BCommon.SetFormStandards(Me)
            Call LoadData()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "frmFirm_Load")
        End Try
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Try
            Me.Close()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "Button1_Click")
        End Try
    End Sub

    Private Function isUpdate() As Boolean
        Try
            Dim dtLoadData As New DataTable
            'blnFlagAddType = True
            blnCountryFlag = True
            blnStateFlag = True
            blnCityFlag = True
            dtLoadData = BFirm.GetData()

            If dtLoadData.Rows.Count > 0 Then
                If Trim(txtFirmName.Text) <> dtLoadData.Rows(0).Item("FirmName") _
                Or Trim(txtShortName.Text) <> dtLoadData.Rows(0).Item("ShortTitle") Or Trim(txtLSTNo.Text) <> dtLoadData.Rows(0).Item("LSTNO") _
                Or Trim(txtCSTNo.Text) <> dtLoadData.Rows(0).Item("CSTNO") Or Trim(txtFDA.Text) <> dtLoadData.Rows(0).Item("FDALicenseNo") Then
                    'Or Trim(dtpDate.Text) <> dtLoadData.Rows(0).Item("FirmStartDate") Then
                    Return True
                Else
                    Return isEqual(BFirm.GetFirmInfo())
                End If
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isUpdate")
        End Try
    End Function

    Private Function isEqual(ByVal intaddID As Integer) As Boolean
        Try
            Dim dtAddr As New DataTable
            dtAddr = BFirm.ShowAddr(intaddID)
            With address(0)
                If .Description1 <> dtAddr.Rows(0).Item("addDesc1") Or _
                .PinCode <> dtAddr.Rows(0).Item("PinCode") Or .PhoneNo1 <> dtAddr.Rows(0).Item("Phone1") Or .PhoneNo2 <> dtAddr.Rows(0).Item("Phone2") Or _
                .Fax <> dtAddr.Rows(0).Item("Fax") Or .EmailID <> dtAddr.Rows(0).Item("MailID") Or _
                .WebSiteAddress <> dtAddr.Rows(0).Item("WebSite") Then
                    Return True
                    Exit Function
                End If
            End With
            Return False
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isEqual")
            Return False
        End Try
    End Function

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Call LoadData()
    End Sub

    Private Sub txtFirmName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFirmName.KeyDown
        Try
            'Kiran@ITS on 20071120;Added for Shortcut key Woking 
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then txtShortName.Focus()
            If e.Shift = True Then
                If (e.KeyCode >= 48 And e.KeyCode <= 48 + 10) Or (e.KeyCode >= 96 And e.KeyCode <= 96 + 10) Or e.KeyCode = 190 Or e.KeyCode = 222 Then
                    e.SuppressKeyPress = True
                End If
            End If
            If BCommon.ValidateText(e.KeyCode, "ALFNUM") = False Or e.KeyCode = 191 Then    'Divya:Modified for restricting ForwardSlash(keyCode-191)
                e.SuppressKeyPress = True
            End If
            If e.KeyCode = 222 Or e.KeyCode = 55 Or e.KeyCode = 57 Or e.KeyCode = 48 Then e.SuppressKeyPress = False '&(KeyCode 55), SingleQuote(keyCode 222), LeftParanthesis(57), RightParanthesis(48)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtFirmName_KeyDown")
        End Try
    End Sub

    Private Sub txtShortName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtShortName.KeyDown
        Try
            'Kiran@ITS on 20071120;Added for Shortcut key Woking
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then txtLSTNo.Focus()
            If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "ALF", False)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtShortName_KeyDown")
        End Try
    End Sub

    Private Sub txtLSTNo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLSTNo.KeyDown
        Try
            'Kiran@ITS on 20071120;Added for Shortcut key Woking
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then txtCSTNo.Focus()
            If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "ALFTEXT", False)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtLSTNo_KeyDown")
        End Try
    End Sub

    Private Sub txtCSTNo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCSTNo.KeyDown
        Try
            'Kiran@ITS on 20071120;Added for Shortcut key Woking
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then txtFDA.Focus()
            If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "ALFTEXT", False)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtCSTNo_KeyDown")
        End Try
    End Sub

    Private Sub txtFDA_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFDA.KeyDown
        Try
            'Kiran@ITS on 20071120;Added for Shortcut key Woking
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then dtpDate.Focus()
            If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "ALFTEXT", False)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtFDA_KeyDown")
        End Try
    End Sub

    Private Sub txtFax_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFax.KeyUp
        Try
            If (BCommon.IsInteger(txtFax.Text) = False) Then txtFax.Focus() : txtFax.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtFax_KeyUp")
        End Try
    End Sub

    Private Sub txtPhone1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone1.KeyUp
        Try
            If (BCommon.IsInteger(txtPhone1.Text) = False) Then txtPhone1.Focus() : txtPhone1.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtPhone1_KeyUp")
        End Try
    End Sub

    Private Sub txtPhone2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone2.KeyUp
        Try
            If (BCommon.IsInteger(txtPhone2.Text) = False) Then txtPhone2.Focus() : txtPhone2.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtPhone2_KeyUp")
        End Try
    End Sub

    Private Sub txtPinCode_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPinCode.KeyUp
        Try
            If (BCommon.IsInteger(txtPinCode.Text) = False) Then txtPinCode.Focus() : txtPinCode.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtPinCode_KeyUp")
        End Try
    End Sub

    Private Sub cmbCountry_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbCountry.SelectedValueChanged
        If blnCountryFlag = False Then Exit Sub
        Call GetCountryState()
    End Sub

    Private Sub dtpDate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpDate.KeyDown
        If e.KeyCode = Keys.Enter Then
            If btnUpdate.Text = "&Save" Then
                dtpFinStart.Focus()
            Else
                txtAddr1.Focus()
                txtAddr1.SelectionLength = 0
            End If
        End If
    End Sub

    Private Sub txtAddr1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtAddr1.KeyDown
        If e.Alt Then Exit Sub
        If e.KeyCode = Keys.Enter Then
            cmbCountry.Focus()
        Else
            If BCommon.ValidateText(e.KeyCode, "ALFTEXT", False) = False Then
                e.SuppressKeyPress = True
            End If
        End If        
    End Sub

    Private Sub txtEmail_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEmail.KeyDown
        If e.KeyCode = Keys.Enter Then txtWebSite.Focus()
    End Sub

    Private Sub txtWebSite_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtWebSite.KeyDown
        If e.KeyCode = Keys.Enter Then btnUpdate.Focus()
    End Sub

    Private Sub dtpFinStart_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpFinStart.KeyDown
        If e.KeyCode = Keys.Enter Then
            If btnUpdate.Text = "&Save" Then
                txtAddr1.Focus()
            End If
        End If
    End Sub

    Private Sub dtpFinEnd_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpFinEnd.KeyDown
        If e.KeyCode = Keys.Enter Then
            txtAddr1.Focus()

        End If

    End Sub
End Class